package com.jzlw.huozhuduan.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;


import com.jzlw.huozhuduan.R;
import com.jzlw.huozhuduan.appction.Global;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

//支付dialog
public class MyWalletDialog extends Dialog {


    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.ll_zfb)
    LinearLayout llZfb;
    @BindView(R.id.ll_wx)
    LinearLayout llWx;
    @BindView(R.id.rl_btn_ok)
    RelativeLayout rlBtnOk;
    private Context context;
    private View view;

    public MyWalletDialog(@NonNull Context context) {
        super(context,R.style.Theme_Light_PayDialog);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        view = LayoutInflater.from(context).inflate(R.layout.dialog_pay, null);
        setContentView(view);
        ButterKnife.bind(this, view);

    }


    private View.OnClickListener onClickListener;


    public void setPayDialog(View.OnClickListener onClickListener){
        this.onClickListener = onClickListener;
    }


    @OnClick({R.id.iv_back, R.id.ll_zfb, R.id.ll_wx,R.id.rl_btn_ok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                dismiss();
                if (onClickListener == null) {
                    onClickListener.onClick(null);
                }
                break;
            case R.id.rl_btn_ok:
                dismiss();
                if (onClickListener != null) {
                    onClickListener.onClick(view);
                }
                break;
            case R.id.ll_zfb:
                zfbPay();
                break;
            case R.id.ll_wx:
                wxPay();
                break;
        }
    }

    /**
     * 微信支付
     */
    private void wxPay() {
        llWx.setSelected(true);
        llZfb.setSelected(false);
        Global.getInstance().setPay(2);
    }

    /**
     * 支付包支付
     */
    private void zfbPay() {
        llWx.setSelected(false);
        llZfb.setSelected(true);
        Global.getInstance().setPay(1);
    }
}
